{extend name="admin/base" /}
{block name="main"}

<div class="infoTab">
    <ul id="myTab" class="nav nav-tabs">
        <li class="active">
            <a href="#shopInfo" data-toggle="tab" class="infoSingle">店铺信息</a>
        </li>
        <li><a href="#registerInfo" data-toggle="tab" class="infoSingle">注册信息</a></li>
    </ul>
    <div id="myTabContent" class="tab-content">
        <div class="tab-pane fade in active" id="shopInfo">
            <form class="form-horizontal widthFixedForm" role="form" id="shopInfoForm">
                <!--店铺信息-->
                <div class="form-group">
                    <div class="col-md-2" style="text-align: right">店铺版本</div>
                    <div class="col-md-8">
                        {$shop_info['instance_type_info']['type_name']}
                    </div>
                </div>
                <!--店铺名称-->
                <div class="form-group">
                    <label for="shopsName" class="col-md-2 control-label fw">店铺名称</label>
                    <div class="col-md-8">
                        <input type="text" class="form-control" id="shopsName" name="shopsName" value="{$shop_info['base_info']['shop_name']}" required title="店铺名称不能为空">
                    </div>
                </div>
                <!--所属分类-->
                <div class="form-group">
                    <label for="shopsName" class="col-md-2 control-label fw">所属分类</label>
                    <div class="col-md-8">
                        <select id="group_id" name="group_id" class="form-control" required title="请选择所属分类">
                            {foreach name="group_list" item="group"}
                            <option value="{$group.shop_group_id}" {if condition="$shop_info['group_info']['shop_group_id'] eq $group.shop_group_id"} selected {/if}>{$group.group_name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <!--店铺logo-->
                <div class="form-group">
                    <label for="Logo" class="col-md-2 control-label fw"><span class="red">*</span>店铺logo</label>
                    <div class="col-sm-5">
                        <div class="picture-list" id="Logo">
                            {if $shop_info['base_info']['shop_logo_img']}
                            <a href="javascript:void(0);" class="close-box"><i class="icon icon-danger" style="margin-right:10px;" title="删除"></i><img data-id="{if $shop_info['base_info']['shop_logo']}{$shop_info['base_info']['shop_logo']}{/if}" src="{:__IMG($shop_info['base_info']['shop_logo_img'])}"></a>
                            {else}
                            <a href="javascript:void(0);" class="plus-box" data-toggle="singlePicture"><i class="icon icon-plus"></i></a>
                            <input type="text" class="visibility" required data-visi-type="singlePicture" name="picture-icon">
                            {/if}
                        </div>
                        <!--<input type="hidden" id="Logo" class="J-pic" value="{if $shop_info['base_info']['shop_logo']}{$shop_info['base_info']['shop_logo']}{/if}"/>-->
                        <p class="help-block">建议400 * 200，支持JPG\GIF\PNG格式</p>
                    </div>
                </div>
                <!--客服qq-->
                <div class="form-group">
                    <label for="shop_qq" class="col-md-2 control-label fw"><span class="red">*</span>客服qq</label>
                    <div class="col-md-8">
                        <input type="text" class="form-control" id="shop_qq" name="shop_qq" value="{$shop_info['base_info']['shop_qq']}" required >
                    </div>
                </div>
                <!--商家电话-->
                <div class="form-group">
                    <label for="tel" class="col-md-2 control-label fw"><span class="red">*</span>商家电话</label>
                    <div class="col-md-8">
                        <input type="text" class="form-control" id="shop_phone" name="shop_phone" value="{$shop_info['base_info']['shop_phone']}" required>
                    </div>
                </div>
                <!--店铺介绍-->
                <div class="form-group">
                    <label for="shop_intro" class="col-md-2 control-label fw">店铺介绍</label>
                    <div class="col-md-8">
                        <textarea id="shop_intro" name="shop_intro" class="form-control ta_resize" rows="4">{$shop_info['base_info']['shop_intro']}</textarea>
                    </div>
                </div>
                <!--保存-->
                <div class="form-group add_back">
                    <label class="col-md-2"></label>
                    <div class="col-md-8">
                        <button type="submit" class="btn add2">保存</button>
                    </div>
                </div>
            </form>
        </div>
        <div class="tab-pane fade" id="registerInfo">
            <form class="form-horizontal widthFixedForm" role="form">
                <div class="screen-title"><span class="text">企业或个人信息</span></div>
                {if $shop_info['company_info']['apply_type']==2}
                <!--公司名称-->
                <div class="form-group">
                    <label for="company_name" class="col-md-2 control-label fw">公司名称</label>
                    <div class="col-md-8">
                        <input type="text" class="form-control" id="company_name" name="company_name" value="{$shop_info['company_info']['company_name']}">
                    </div>
                </div>
                {/if}
                <!--公司所在地-->
                <div class="form-group">
                    <label for="address" class="col-md-2 control-label fw">{if $shop_info['company_info']['apply_type']==2}公司所在地{else}联系地址{/if}</label>
                    <div class="col-md-5">
                        <div  class="area-form-group" data-toggle="distpicker">
                            <select name="province" id="selProvinces" style='width:180px;float:left;'  class="form-control getProvince">
                                    <option value="-1">请选择省...</option>
                            </select>
                            <select name="city" id="selCities" style='width:180px;float:left;' class="form-control getSelCity">
                                    <option value="-1">请选择市...</option>
                            </select>
                            <select name="district" id="selDistricts" style='width:180px;float:left' class="form-control">
                                    <option value="-1">请选择区...</option>
                            </select>
                        </div>
                    </div>
                </div>
                <!--公司详细地址-->
                <div class="form-group">
                    <label for="company_address_detail" class="col-md-2 control-label fw">详细地址</label>
                    <div class="col-md-8">
                        <input type="text" class="form-control" id="company_address_detail" name="company_address_detail" value="{$shop_info['company_info']['company_address_detail']}">
                    </div>
                </div>
                {if $shop_info['company_info']['apply_type']=='2'}
                <div class="form-group J-company">
                    <label class="col-md-2 control-label">公司类型</label>
                    <div class="col-md-8">
                        <select id="company_type" name="company_type" class="form-control">
                            <option value="私企" {if condition="$shop_info['company_info']['company_type'] eq '私企'"} selected {/if}>私企</option>
                            <option value="个体" {if condition="$shop_info['company_info']['company_type'] eq '个体'"} selected {/if}>个体</option>
                            <option value="外企" {if condition="$shop_info['company_info']['company_type'] eq '外企'"} selected {/if}>外企</option>
                            <option value="中外合资" {if condition="$shop_info['company_info']['company_type'] eq '中外合资'"} selected {/if}>中外合资</option>
                        </select>
                    </div>
                </div>
                <!--公司电话-->
                <div class="form-group">
                    <label for="company_phone" class="col-md-2 control-label fw">公司电话</label>
                    <div class="col-md-8">
                        <input type="text" class="form-control" id="company_phone" name="company_phone" value="{$shop_info['company_info']['company_phone']}">
                    </div>
                </div>
                <!--员工人数-->
                <div class="form-group">
                    <label for="company_employee_count" class="col-md-2 control-label fw">员工人数</label>
                    <div class="col-md-8">
                        <input type="number" class="form-control"  min='0' id="company_employee_count" name="company_employee_count" value="{$shop_info['company_info']['company_employee_count']}">
                    </div>
                </div>
                <!--注册资金-->
                <div class="form-group">
                    <label for="company_registered_capital" class="col-md-2 control-label fw">注册资金（万元）</label>
                    <div class="col-md-8">
                        <input type="number" class="form-control"  min='0' id="company_registered_capital" name="company_registered_capital" value="{$shop_info['company_info']['company_registered_capital']}">
                    </div>
                </div>
                {/if}
                <div class="form-group">
                        <label class="col-md-2 control-label">联系人姓名</label>
                        <div class="col-md-8">
                            <input type="text" class="form-control" id="contacts_name" placeholder="请输入联系人姓名" value="{$shop_info['company_info']['contacts_name']}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">联系人电话</label>
                        <div class="col-md-8">
                            <input type="text" class="form-control" id="contacts_phone" placeholder="请输入联系人电话" value="{$shop_info['company_info']['contacts_phone']}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">电子邮箱</label>
                        <div class="col-md-8">
                            <input type="text" class="form-control" id="contacts_email" placeholder="请输入电子邮箱" value="{$shop_info['company_info']['contacts_email']}">
                        </div>
                    </div>
                {if $shop_info['company_info']['apply_type']=='2'}
                <div class="screen-title"><span class="text">营业信息</span></div>
                <!--营业执照号-->
                <div class="form-group">
                        <label class="col-md-2 control-label">营业执照号</label>
                        <div class="col-md-8">
                            <input type="text" class="form-control" id="business_licence_number" placeholder="请输入营业执照号" value="{$shop_info['company_info']['business_licence_number']}">
                        </div>
                    </div>
                <div class="form-group">
                    <label for="business_licence_number_electronic" class="col-md-2 control-label fw">营业执照</label>
                    <div class="col-sm-5">
                        <!--<a href="javascript:void(0)"  onclick="showAlbum(this, 1, 'selectpic(this)');" style="display: inline-block;">
                            <img class="limit100" src="{if $shop_info['company_info']['business_licence_number_electronic']}{$shop_info['company_info']['business_licence_number_electronic']}{else}ADMIN_IMG/aa.png{/if}" alt="">
                            <input type="hidden" id="business_licence_number_electronic" class="J-pic" value="{$shop_info['company_info']['business_licence_number_electronic']}"/>
                        </a>-->
                        <div class="picture-list" id="business_licence_number_electronic">
                            {if $shop_info['company_info']['business_licence_number_electronic']}
                            <a href="javascript:void(0);" class="close-box"><i class="icon icon-danger" style="margin-right:10px;" title="删除"></i><img src="{$shop_info['company_info']['business_licence_number_electronic']}"></a>
                            {else}
                            <a href="javascript:void(0);" class="plus-box" data-toggle="singlePicture"><i class="icon icon-plus"></i></a>
                            {/if}
                        </div>
                    </div>
                </div>
                <!--法定经营范围-->
                <div class="form-group">
                    <label for="business_sphere" class="col-md-2 control-label fw">法定经营范围</label>
                    <div class="col-md-8">
                        <input type="text" class="form-control" id="business_sphere" name="business_sphere" value="{$shop_info['company_info']['business_sphere']}">
                    </div>
                </div>
                {/if}
                <div class="screen-title"><span class="text">身份证</span></div>
                 <div class="form-group">
                        <label class="col-md-2 control-label">{if $shop_info['company_info']['apply_type']=='2'}法人{/if}身份证号码</label>
                        <div class="col-md-8">
                            <input type="text" class="form-control" id="contacts_card_no" placeholder="请输入身份证号码" value="{$shop_info['company_info']['contacts_card_no']}">
                        </div>
                    </div>
                <!--手持身份证正面-->
                <div class="form-group">
                    <label for="idcard_positive" class="col-md-2 control-label fw">{if $shop_info['company_info']['apply_type']=='2'}法人{/if}手持身份证照片</label>
                    <div class="col-md-2">
                        <div class="picture-list" id="contacts_card_electronic_1">
                            {if $shop_info['company_info']['contacts_card_electronic_1']}
                            <a href="javascript:void(0);" class="close-box"><i class="icon icon-danger" style="margin-right:10px;" title="删除"></i><img src="{$shop_info['company_info']['contacts_card_electronic_1']}"></a>
                            {else}
                            <a href="javascript:void(0);" class="plus-box" data-toggle="singlePicture"><i class="icon icon-plus"></i></a>
                            {/if}
                        </div>
                    </div>
                </div>
                <!--身份证正面-->
                <div class="form-group">
                    <label for="idcard_positive" class="col-md-2 control-label fw">身份证正面照</label>
                    <div class="col-md-5">
                        <div class="picture-list" id="contacts_card_electronic_2">
                            {if $shop_info['company_info']['contacts_card_electronic_2']}
                            <a href="javascript:void(0);" class="close-box"><i class="icon icon-danger" style="margin-right:10px;" title="删除"></i><img src="{$shop_info['company_info']['contacts_card_electronic_2']}"></a>
                            {else}
                            <a href="javascript:void(0);" class="plus-box" data-toggle="singlePicture"><i class="icon icon-plus"></i></a>
                            {/if}
                            
                        </div>
                    </div>
                </div>
                <!--身份证反面-->
                <div class="form-group">
                    <label for="idcard_opposite" class="col-md-2 control-label fw">身份证反面照</label>
                    <div class="col-md-8">
                        <div class="picture-list" id="contacts_card_electronic_3">
                            {if $shop_info['company_info']['contacts_card_electronic_3']}
                            <a href="javascript:void(0);" class="close-box"><i class="icon icon-danger" style="margin-right:10px;" title="删除"></i><img src="{$shop_info['company_info']['contacts_card_electronic_3']}"></a>
                            {else}
                            <a href="javascript:void(0);" class="plus-box" data-toggle="singlePicture"><i class="icon icon-plus"></i></a>
                            {/if}
                        </div>
                    </div>
                </div>
                <!--保存-->
                <div class="form-group add_back">
                    <label class="col-md-2"></label>
                    <div class="col-md-5">
                        <button type="button" class="btn add1">保存</button>
                    </div>
                </div>
                <input type="hidden" id="pid" value="{$shop_info['company_info']['company_province_id']}">
                <input type="hidden" id="cid" value="{$shop_info['company_info']['company_city_id']}">
                <input type="hidden" id="aid" value="{$shop_info['company_info']['company_district_id']}">
            </form>
        </div>

    </div>
</div>
<!-- page end -->


<!-- /.modal -->
{/block}
{block name="script"}
<script>
require(['utilAdmin'], function (utilAdmin) {    
var pid = 0, cid = 0, aid = 0;
$(document).ready(function () {
    initProvince("#selProvinces");
    getProvince();
    getSelCity();
    // $('#shopInfoForm').validate();
});
function initProvince(obj) {
    pid = $('#pid').val();
    $.ajax({
        type: "post",
        url: "{:__URL('ADMIN_MAIN/Shop/getprovince')}",
        dataType: "json",
        success: function (data) {
            if (data != null && data.length > 0) {
                var str = "";
                for (var i = 0; i < data.length; i++) {
                    if (pid == data[i].province_id) {
                        str += '<option selected value="' + data[i].province_id + '">' + data[i].province_name + '</option>';
                    } else {
                        str += '<option value="' + data[i].province_id + '">' + data[i].province_name + '</option>';
                    }
                }
                $(obj).append(str);
            }
        }
    });
}
//选择省份弹出市区
$('.getProvince').on('change', function () {
    var id = $('#selProvinces').val();
    if (id == -1) {
        id = pid;
    }
    cid = $('#cid').val();
    $.ajax({
        type: "post",
        url: "{:__URL('ADMIN_MAIN/Shop/getcity')}",
        dataType: "json",
        data: {
            "province_id": id
        },
        success: function (data) {
            if (data != null && data.length > 0) {
                var str = "<option value='-1'>请选择市</option>";
                for (var i = 0; i < data.length; i++) {
                    if (cid == data[i].city_id) {
                        str += '<option selected value="' + data[i].city_id + '">' + data[i].city_name + '</option>';
                    } else {
                        str += '<option  value="' + data[i].city_id + '">' + data[i].city_name + '</option>';
                    }
                }
                $('#selCities').html(str);
            }
        }
    });
});
function getProvince() {
    var id = $('#selProvinces').val();
    if (id == -1) {
        id = pid;
    }
    cid = $('#cid').val();
    $.ajax({
        type: "post",
        url: "{:__URL('ADMIN_MAIN/Shop/getcity')}",
        dataType: "json",
        data: {
            "province_id": id
        },
        success: function (data) {
            if (data != null && data.length > 0) {
                var str = "<option value='-1'>请选择市</option>";
                for (var i = 0; i < data.length; i++) {
                    if (cid == data[i].city_id) {
                        str += '<option selected value="' + data[i].city_id + '">' + data[i].city_name + '</option>';
                    } else {
                        str += '<option  value="' + data[i].city_id + '">' + data[i].city_name + '</option>';
                    }
                }
                $('#selCities').html(str);
            }
        }
    });
}
//选择市区弹出区域
$('.getSelCity').on('change', function () {
    var id = $('#selCities').val();
    aid = $('#aid').val();
    if (id == -1) {
        id = cid;
    }
    $.ajax({
        type: "post",
        url: "{:__URL('ADMIN_MAIN/Shop/getdistrict')}",
        dataType: "json",
        data: {
            "city_id": id
        },
        success: function (data) {
            if (data != null && data.length > 0) {
                var str = "<option value='-1'>请选择区</option>";
                for (var i = 0; i < data.length; i++) {
                    if (aid == data[i].district_id) {
                        str += '<option selected value="' + data[i].district_id + '">' + data[i].district_name + '</option>';
                    } else {
                        str += '<option value="' + data[i].district_id + '">' + data[i].district_name + '</option>';
                    }

                }
                $('#selDistricts').html(str);
            }
        }
    });
});
function getSelCity() {
    var id = $('#selCities').val();
    aid = $('#aid').val();
    if (id == -1) {
        id = cid;
    }
    $.ajax({
        type: "post",
        url: "{:__URL('ADMIN_MAIN/Shop/getdistrict')}",
        dataType: "json",
        data: {
            "city_id": id
        },
        success: function (data) {
            if (data != null && data.length > 0) {
                var str = "<option value='-1'>请选择区</option>";
                for (var i = 0; i < data.length; i++) {
                    if (aid == data[i].district_id) {
                        str += '<option selected value="' + data[i].district_id + '">' + data[i].district_name + '</option>';
                    } else {
                        str += '<option value="' + data[i].district_id + '">' + data[i].district_name + '</option>';
                    }

                }
                $('#selDistricts').html(str);
            }
        }
    });
}
function setShopConfigAjax() {
    utilAdmin.validate('#shopInfoForm',function(form){
        var shop_logo = $("#Logo").find("img").data("id");
        var shop_qq = $("#shop_qq").val();
        var shop_phone = $("#shop_phone").val();
        var shop_intro = $("#shop_intro").val();
        var shop_name = $("#shopsName").val();
        var group_id = $("#group_id").val();
        $.ajax({
            type: "post",
            url: "{:__URL('ADMIN_MAIN/Shop/shopConfig')}",
            data: {
                'shop_logo': shop_logo,
                'shop_qq': shop_qq,
                'shop_intro': shop_intro,
                'shop_phone': shop_phone,
                'shop_name': shop_name,
                'group_id': group_id
            },
            success: function (data) {
                if (data["code"] > 0) {
                    // layer.msg(data["message"], {icon: 1, time: 1000});
                    utilAdmin.message(data["message"],'success');
                } else {
                    // layer.msg(data["message"], {icon: 2, time: 1000});
                    utilAdmin.message(data["message"],'danger');
                }
            }
        });
    });

}
function setCompanyConfigAjax() {
    var company_name = $("#company_name").val();
    var company_province_id = $("#selProvinces").val();
    var company_city_id = $("#selCities").val();
    var company_district_id = $("#selDistricts").val();
    var company_type = $("#company_type").val();
    var company_address_detail = $("#company_address_detail").val();
    var company_phone = $("#company_phone").val();
    var company_employee_count = $("#company_employee_count").val();
    var company_registered_capital = $("#company_registered_capital").val();
    var contacts_name = $("#contacts_name").val();
    var contacts_phone = $("#contacts_phone").val();
    var contacts_email = $("#contacts_email").val();
    var business_licence_number = $("#business_licence_number").val();
    var business_sphere = $("#business_sphere").val();
    var business_licence_number_electronic = $("#business_licence_number_electronic").find("img").attr("src");
    var contacts_card_no = $("#contacts_card_no").val();
    var contacts_card_electronic_1 = $("#contacts_card_electronic_1").find("img").attr("src");
    var contacts_card_electronic_2 = $("#contacts_card_electronic_2").find("img").attr("src");
    var contacts_card_electronic_3 = $("#contacts_card_electronic_3").find("img").attr("src");
    $.ajax({
        type: "post",
        url: "{:__URL('ADMIN_MAIN/Shop/companyConfig')}",
        data: {
            'company_name': company_name,
            'company_type': company_type,
            'company_province_id': company_province_id,
            'company_city_id': company_city_id,
            'company_district_id': company_district_id,
            'company_address_detail': company_address_detail,
            'company_phone': company_phone,
            'company_employee_count': company_employee_count,
            'company_registered_capital': company_registered_capital,
            'contacts_name': contacts_name,
            'contacts_phone': contacts_phone,
            'contacts_email': contacts_email,
            'business_licence_number': business_licence_number,
            'business_sphere': business_sphere,
            'business_licence_number_electronic': business_licence_number_electronic,
            'contacts_card_no': contacts_card_no,
            'contacts_card_electronic_1': contacts_card_electronic_1,
            'contacts_card_electronic_2': contacts_card_electronic_2,
            'contacts_card_electronic_3': contacts_card_electronic_3,
        },
        success: function (data) {
            if (data["code"] > 0) {
                // layer.msg(data["message"], {icon: 1, time: 1000});
                utilAdmin.message(data["message"],'success');
            } else {
                utilAdmin.message(data["message"],'danger');
            }
        }
    });
}
function selectpic(event) {
    $('#licenseImg').modal('hide');
    var chooseId = $('#J-choose').val();
    var chooseImg = $('#J-choose_img').val();
    if (chooseId === '') {
        return;
    }
    var dom = $(event).attr('dom');
    if(dom=='Logo'){
        $('#' + dom).val(chooseId);
    }else{
        $('#' + dom).val(chooseImg);
    }
    $('#' + dom).siblings('img').removeAttr('style').attr('src', chooseImg);
    $('#shop_logo-error').hide();
}

$('body').on('click','.add1',function(){
    setCompanyConfigAjax();
});

    setShopConfigAjax();

})
</script>
{/block}